home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / MATH / NRPAS13 / MIDPNT.DEM < prev    next >
Text File  |  1991-04-29  |  689b  |  36 lines

  1. PROGRAM d4r5(input,output);
  2. (* driver for routine MIDPNT *)
  3. CONST
  4.    nmax=10;
  5. VAR
  6.    a,b,s : real;
  7.    i,glit : integer;
  8.  
  9. FUNCTION func(x: real): real;
  10. (* Function for testing integration *)
  11. BEGIN
  12.    func := 1.0/sqrt(x)
  13. END;
  14.  
  15. FUNCTION fint(x: real): real;
  16. (* Integral of 'func' *)
  17. BEGIN
  18.    fint := 2.0*sqrt(x)
  19. END;
  20.  
  21. (*$I MODFILE.PAS *)
  22. (*$I MIDPNT.PAS *)
  23.  
  24. BEGIN
  25.    a := 0.0;
  26.    b := 1.0;
  27.    writeln;
  28.    writeln ('Integral of func computed with MIDPNT');
  29.    writeln ('Actual value of integral is',(fint(b)-fint(a)):7:4);
  30.    writeln ('n':6,'Approx. integral':29);
  31.    FOR i := 1 to nmax DO BEGIN
  32.       midpnt(a,b,s,i);
  33.       writeln (i:6,s:24:6)
  34.    END
  35. END.
  36.